]> dgit.raspbian.org Git - gnome-shell.git/commitdiff
ShellButtonBox: Use default handlers, not self-connections
authorOwen W. Taylor <otaylor@fishsoup.net>
Sat, 29 Aug 2009 16:31:15 +0000 (12:31 -0400)
committerOwen W. Taylor <otaylor@fishsoup.net>
Sat, 29 Aug 2009 19:20:18 +0000 (15:20 -0400)
There's seldom a good justification for connecting to signals on
yourself rather than using the default handler slots in the class.

But in particular using the default handler slots means that
an application can connect to ::button-press-event and get in
before the default handling, to implement a button that does
something on press.

http://bugzilla.gnome.org/show_bug.cgi?id=593503

src/shell-button-box.c

index 25808a45a645d8f5e19f44607f6c677e58e8349d..56dd944108525dcc063437110b1adf65aae779a2 100644 (file)
@@ -79,13 +79,14 @@ shell_button_box_contains (ShellButtonBox     *box,
 }
 
 static gboolean
-shell_button_box_on_enter (ShellButtonBox     *box,
-                           ClutterEvent       *event,
-                           gpointer            user_data)
+shell_button_box_enter_event (ClutterActor         *actor,
+                              ClutterCrossingEvent *event)
 {
-  if (shell_button_box_contains (box, event->crossing.related))
+  ShellButtonBox *box = SHELL_BUTTON_BOX (actor);
+
+  if (shell_button_box_contains (box, event->related))
     return TRUE;
-  if (!shell_button_box_contains (box, clutter_event_get_source (event)))
+  if (!shell_button_box_contains (box, event->source))
     return TRUE;
 
   set_hover (box, TRUE);
@@ -96,11 +97,12 @@ shell_button_box_on_enter (ShellButtonBox     *box,
 }
 
 static gboolean
-shell_button_box_on_leave (ShellButtonBox     *box,
-                           ClutterEvent       *event,
-                           gpointer            user_data)
+shell_button_box_leave_event (ClutterActor         *actor,
+                              ClutterCrossingEvent *event)
 {
-  if (shell_button_box_contains (box, event->crossing.related))
+  ShellButtonBox *box = SHELL_BUTTON_BOX (actor);
+
+  if (shell_button_box_contains (box, event->related))
     return TRUE;
 
   set_hover (box, FALSE);
@@ -110,17 +112,15 @@ shell_button_box_on_leave (ShellButtonBox     *box,
 }
 
 static gboolean
-shell_button_box_on_press (ShellButtonBox     *box,
-                           ClutterEvent       *event,
-                           gpointer            user_data)
+shell_button_box_button_press_event (ClutterActor       *actor,
+                                     ClutterButtonEvent *event)
 {
-  ClutterActor *source;
+  ShellButtonBox *box = SHELL_BUTTON_BOX (actor);
 
   if (box->priv->held)
     return TRUE;
 
-  source = clutter_event_get_source (event);
-  if (!shell_button_box_contains (box, source))
+  if (!shell_button_box_contains (box, event->source))
     return FALSE;
 
   box->priv->held = TRUE;
@@ -132,21 +132,18 @@ shell_button_box_on_press (ShellButtonBox     *box,
 }
 
 static gboolean
-shell_button_box_on_release (ShellButtonBox     *box,
-                             ClutterEvent       *event,
-                             gpointer            user_data)
+shell_button_box_button_release_event (ClutterActor       *actor,
+                                       ClutterButtonEvent *event)
 {
-  ClutterActor *source;
+  ShellButtonBox *box = SHELL_BUTTON_BOX (actor);
 
   if (!box->priv->held)
     return TRUE;
 
-  source = clutter_event_get_source (event);
-
   box->priv->held = FALSE;
   clutter_ungrab_pointer ();
 
-  if (!shell_button_box_contains (box, source))
+  if (!shell_button_box_contains (box, event->source))
     return FALSE;
 
   set_pressed (box, FALSE);
@@ -204,10 +201,16 @@ static void
 shell_button_box_class_init (ShellButtonBoxClass *klass)
 {
   GObjectClass *gobject_class = G_OBJECT_CLASS (klass);
+  ClutterActorClass *actor_class = CLUTTER_ACTOR_CLASS (klass);
 
   gobject_class->get_property = shell_button_box_get_property;
   gobject_class->set_property = shell_button_box_set_property;
 
+  actor_class->enter_event = shell_button_box_enter_event;
+  actor_class->leave_event = shell_button_box_leave_event;
+  actor_class->button_press_event = shell_button_box_button_press_event;
+  actor_class->button_release_event = shell_button_box_button_release_event;
+
   /**
    * ShellButtonBox::activate
    * @box: The #ShellButtonBox
@@ -275,9 +278,4 @@ shell_button_box_init (ShellButtonBox *self)
 {
   self->priv = G_TYPE_INSTANCE_GET_PRIVATE (self, SHELL_TYPE_BUTTON_BOX,
                                             ShellButtonBoxPrivate);
-
-  g_signal_connect (G_OBJECT (self), "enter-event", G_CALLBACK(shell_button_box_on_enter), NULL);
-  g_signal_connect (G_OBJECT (self), "leave-event", G_CALLBACK(shell_button_box_on_leave), NULL);
-  g_signal_connect (G_OBJECT (self), "button-press-event", G_CALLBACK(shell_button_box_on_press), NULL);
-  g_signal_connect (G_OBJECT (self), "button-release-event", G_CALLBACK(shell_button_box_on_release), NULL);
 }